package com.msg.test01;

import java.sql.*;

/**
 * @author wuJiaWei
 * @version 1.0
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //获取连接
        String url="jdbc:mysql://127.0.0.1:3306/msb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true";
//        String url = "jdbc:mysql://localhost:3306/msb?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
        String username = "root";
        String password = "123456";
        Connection conn = DriverManager.getConnection(url, username, password);
        //创建会话
        Statement stmt = conn.createStatement();
        //插入数据
        int bookId = stmt.executeUpdate("insert into t_book values(4,'java','张三',1)");
        //获取插入数据的id
        if (bookId > 0){
            System.out.println("添加成功");
        }
        //关闭数据库资源
        stmt.close();
    }
}
